Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change onehot to oneelement #26

Merged
merged 5 commits into from
Feb 3, 2025
Merged

Change onehot to oneelement #26

merged 5 commits into from
Feb 3, 2025

Conversation

mtfishman
Copy link
Member

@mtfishman mtfishman commented Feb 2, 2025

onehot isn't quite right for the ITensor constructor that creates a tensor with a single nonzero element, see OneHotArrays.jl.

There is precedent from FillArrays.jl and Zygote.jl for calling a sparse array with a single nonzero element OneElement (https://github.com/JuliaArrays/FillArrays.jl), so here I am changing onehot to oneelement.

In the latest, this is implemented based on a new type SparseArraysBase.OneElementArray with an associated generic constructor SparseArraysBase.oneelement in a package extension, see ITensor/SparseArraysBase.jl#26.

See also #5, ITensor/SparseArraysBase.jl#24.

Copy link

codecov bot commented Feb 2, 2025

Codecov Report

Attention: Patch coverage is 50.00000% with 2 lines in your changes missing coverage. Please review.

Project coverage is 48.08%. Comparing base (e9f1be2) to head (917cf55).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
src/quirks.jl 0.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main      #26      +/-   ##
==========================================
+ Coverage   46.23%   48.08%   +1.85%     
==========================================
  Files           5        6       +1     
  Lines         186      183       -3     
==========================================
+ Hits           86       88       +2     
+ Misses        100       95       -5     
Flag Coverage Δ
docs 23.07% <0.00%> (+0.37%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@emstoudenmire
Copy link

I see what you mean. Just from the name "one hot" I would have thought things like having multiple ones and a single row or column would be forbidden (here I am referring to the example at that link). But apparently this is the usage in ML, and also one element is just a much clearer name.

@mtfishman
Copy link
Member Author

I see what you mean. Just from the name "one hot" I would have thought things like having multiple ones and a single row or column would be forbidden (here I am referring to the example at that link). But apparently this is the usage in ML, and also one element is just a much clearer name.

They call that more general case a onehotbatch in OneHotArrays.jl, but still you can see the idea is to find the location of a value in a collection and use that to define a basis vector, so it is a very similar concept to how we use onehot but the application is a bit different. Anyway, I'll probably bring back onehot for backwards compatibility but deprecate it in favor of oneelement.

@mtfishman mtfishman merged commit 7a1ed53 into main Feb 3, 2025
12 checks passed
@mtfishman mtfishman deleted the oneelement branch February 3, 2025 03:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants